<?php

class Core_Backend_Component_Promotion_View_Concessions_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('promotion/concessions/index'), $this->__('share.button.back'));
        if($this->getIdentity()->isAllowAction('promotion_concessions_edit')){
	        $group = $toolbar->createGroup('save');
	        $group->addButton($this->__('share.button.submit'))
	                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(array('status'=>'pending'), 'save') . "')");
	        $group->addButton($this->__('share.button.save'))
	                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(array('status'=>'draft'), 'save') . "')");
        }
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('concessions_form')
                ->addHiddenField('id', 'concessions[id]');
        $form->addTextboxField($this->__('share.label.name'), 'name', 'concessions[name]', TRUE)->addValidateRule('required');
        $form->addSelectField($this->__('promotion.label.concessions_category'), 'category_id', 'concessions[category_id]', TRUE)
                ->bindData($this->getCategories(), 'name', 'id')
                ->addValidateRule('required');
        $form->addDatetimeField($this->__('share.label.start_time'), 'start_time', 'concessions[start_time]')
                ->setFormat('Y-m-d');
        $form->addDatetimeField($this->__('share.label.end_time'), 'end_time', 'concessions[end_time]')
                ->setFormat('Y-m-d');
        $form->addSelectField($this->__('share.label.theme'), 'theme_id', 'concessions[theme_id]')
                ->setOption('--', '')
                ->bindData($this->getThemes(), 'title', 'id');
        $form->addTextboxField($this->__('share.label.tag'), 'tag', 'concessions[tag]');
        $form->addPoiBrowserField('', 'poi_ids', 'concessions[poi_ids][]');
        $form->addTextareaField($this->__('promotion.label.condition'), 'condition', 'concessions[condition]');
        $form->addTextareaField($this->__('promotion.label.mode'), 'mode', 'concessions[mode]');
        $form->addFileBrowserField($this->__('promotion.label.dm'), 'picture', 'concessions[picture]')
                ->setPath('pub/media/promotion/concessions')
                ->setFileType('image')
                ->setCallback('selectDMPictute');
        $form->addTextareaField($this->__('share.label.detail'), 'detail', 'concessions[detail]')->setStyle('height', 200);
        $form->createTab('base_tab', $this->__('promotion.label.base_tab'),
                array('field_name', 'field_category_id', 'field_theme_id', 'field_tag', 'field_start_time', 'field_end_time',
                    'field_condition', 'field_mode', 'field_detail'));
        $form->createTab('picture_tab', $this->__('promotion.label.picture_tab'),
                array('field_picture'));
        $form->createTab('poi_tab', $this->__('promotion.label.poi_tab'),
                array('field_poi_ids'));
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}